package comparisons

import (
	"jvm/instructions/base"
	"jvm/rtda"
)

// Branch if int comparison with zero succeeds
type IFEQ struct{ base.BranchInstruction }

func (i *IFEQ) Execute(jFrame *rtda.JFrame) {
	val := jFrame.OperandStack().PopInt()
	if val == 0 {
		base.Branch(jFrame, i.Offset)
	}
}

type IFNE struct{ base.BranchInstruction }

func (i *IFNE) Execute(jFrame *rtda.JFrame) {
	val := jFrame.OperandStack().PopInt()
	if val != 0 {
		base.Branch(jFrame, i.Offset)
	}
}

type IFLT struct{ base.BranchInstruction }

func (i *IFLT) Execute(jFrame *rtda.JFrame) {
	val := jFrame.OperandStack().PopInt()
	if val < 0 {
		base.Branch(jFrame, i.Offset)
	}
}

type IFLE struct{ base.BranchInstruction }

func (i *IFLE) Execute(jFrame *rtda.JFrame) {
	val := jFrame.OperandStack().PopInt()
	if val <= 0 {
		base.Branch(jFrame, i.Offset)
	}
}

type IFGT struct{ base.BranchInstruction }

func (i *IFGT) Execute(jFrame *rtda.JFrame) {
	val := jFrame.OperandStack().PopInt()
	if val > 0 {
		base.Branch(jFrame, i.Offset)
	}
}

type IFGE struct{ base.BranchInstruction }

func (i *IFGE) Execute(jFrame *rtda.JFrame) {
	val := jFrame.OperandStack().PopInt()
	if val >= 0 {
		base.Branch(jFrame, i.Offset)
	}
}
